import 'package:flutter/material.dart';
import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/ui/pages/commonProblem/qa_entity.dart';
import 'custom_expansion_tile.dart' as custom_expansion_title;

class QAPage extends StatefulWidget {
  final QaQajson qaQajson;

  QAPage({Key key, this.qaQajson}) : super(key: key);

  @override
  _QAPageState createState() => _QAPageState();
}
class _QAPageState extends State<QAPage>  {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colours.c243,
      body: ListView.builder(
          itemCount: widget.qaQajson.children.length,
          itemBuilder: (BuildContext context, int index) {
            return getItem(context, index);
          }),
    );
  }

  Widget getItem(BuildContext context, int index) {
    return Container(
      margin: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(10),
          ScreenUtil().setWidth(10),
          ScreenUtil().setWidth(10),
          ScreenUtil().setWidth(10)),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(6)),
      child: custom_expansion_title.ExpansionTile(
        backgroundColor: Colors.white,
        title: Text(
          "${widget.qaQajson.children[index].uid}、${widget.qaQajson.children[index].name}",
          style: TextStyles.custom(
              30, Colours.appC1, Font.PingFangMedium),
        ),
        children: this.getChildWidgets(widget.qaQajson.children[index]),
      ),
    );
  }

  getChildWidgets(QaQajsonchild children) {
    List<Widget> widgets = [];
    widgets.add(Container(
      alignment: Alignment.centerLeft,
      child: getChildren(children.desc),
    ));

    if (children.child != null) {
      for (int i = 0; i < children.child.length; i++) {
        widgets.add(getChildrenChild(children.child[i].desc));
      }
    }

    return widgets;
  }

  getChildren(String desc) {
    return Container(
      padding: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(10),
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(10)),
      child: Text(desc,
          style: TextStyles.custom(
              28, Colours.appC3, Font.PingFangMedium)),
    );
  }

  getChildrenChild(String des) {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(10),
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(10)),
      child: Text(
        des,
        style:
            TextStyles.custom(28, Colours.appC3, Font.PingFangRegular),
      ),
    );
  }
}


